//数组对象

const arr1 = new Array();//构造函数
const arr2 = [];//自变量

//长度不固定，元素可以不同
//const arr = [0,"green",{}];
const arr = ["red","green","blue"];
console.log(typeof arr);//object
console.log(Array.isArray(arr));//判断是否是一个数组


console.log(arr[1]);
console.log(arr.length);//属性：length = 最大的下标值+1 返回的不是元素个数
//arr[100] = "white"
//console.log(arr.length);

for(let elem of arr){
    //console.log(elem);
}

console.log(arr.indexOf("green"));
console.log(arr.includes("green"));

let color=arr.pop();
console.log(color);
console.log(arr);
arr.push("blue");
console.log(arr);

arr.unshift("white");
console.log(arr);
color=arr.shift();
console.log(color);
console.log(arr);

arr.splice(1,1);
console.log(arr);
arr.splice(1,0,"green");
console.log(arr);

console.log(arr.reverse()); //数组逆序

//生成新数组
//生成子数组
const subArr=arr.slice(1,3);
console.log(subArr);
console.log(subArr===arr);
const concatArr=arr.concat('white','black');
console.log(concatArr);

//clone数组
const cloneArr=['1'].concat(arr);
console.log(cloneArr);

//Array->String
const joinStr=arr.join(":");//拼接
console.log(joinStr);

//String->Array
console.log(joinStr.split(":"));